package com.huadi.firematerialident.dao;

import com.huadi.firematerialident.po.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class AdminDaoImpl implements AdminDao{

    @Autowired
    JdbcTemplate jdbcTemplate;

    public int addAdmin(Admin admin) {
        String sql="insert into Admin values(?,?,?,?,?,?,?,1,now())";
        return jdbcTemplate.update(sql,
                admin.getAdminID(),
                admin.getAdminCount(),
                admin.getAdminPassword(),
                admin.getAdminName(),
                admin.getAdminSex(),
                admin.getAdminBirth(),
                admin.getAdminPhone());
    }

    public int deleteAdminByID(String adminID) {
        String sql="update admin set LogicalAddDel=0,LastModification=now() where AdminID=?";
        return jdbcTemplate.update(sql,adminID);
    }


    public int updateAdmin(Admin admin) {
        String sql="update admin set AdminID=?,AdminCount=?,AdminPassword=?," +
                "AdminName=?,AdminSex=?,AdminBirth=?,AdminPhone=?,LastModification=now() where AdminID=?";
        return jdbcTemplate.update(sql,admin.getAdminID(),
                admin.getAdminCount(),
                admin.getAdminPassword(),
                admin.getAdminName(),
                admin.getAdminSex(),
                admin.getAdminBirth(),
                admin.getAdminPhone(),
                admin.getAdminID());
    }


    public List<Map<String,Object>> selectAdminByID(String adminID) {
        String sql = "select * from admin where AdminID = ?";
        return jdbcTemplate.queryForList(sql,adminID);
    }



    public List<Map<String,Object>> getAllAdmin() {
        String sql="select * from admin";
        return jdbcTemplate.queryForList(sql);
    }
}